
const g = getApp().globalData
const util = g.util


Page({
    data: {
        applyTypeText: '',
        name: '',
        phoneNumber: '',
    },

    onLoad(options) {
        let applyType = options.applyType
        this.applyType = options.applyType
        let applyTypeText = ''
        if (applyType == 1) {
            applyTypeText = '业主'
        } else if (applyType == 2) {
            applyTypeText = '管理员'
        }
        wx.setNavigationBarTitle({
            title: `${applyTypeText}审批`,
        })
        this.setData({
            applyTypeText,
        })
    },

    // 获取姓名
    nameChange(e) {
        this.setData({
            name: e.detail.value
        })

    },

    //获取电话
    phoneChange(e) {
        this.setData({
            phoneNumber: e.detail.value
        })
    },

    //提交
    submit() {
        if (!this.data.name) {
            wx.showToast({
                title: '姓名为必填项',
            })
            return
        }

        if (!this.data.phoneNumber) {
            wx.showToast({
                title: '手机号为必填项',
            })
            return
        }
        let url = `approve/add`
        let body = {
            user_name: this.data.name,
            mobile: this.data.phoneNumber,
            type: this.applyType,
        }

        util.httpPost({
            url,
            body,
            header: { authorization: g.userInfo.token },
            fn: res => {
                wx.showToast({
                    title: '提交成功',
                })
                wx.navigateBack({
                    delta: 1,
                })
            },
            failFn: failRes => {
                wx.showToast({
                    title: failRes.data.msg,
                })
            }
        })

    }
})